package com.demo.webapp.kcfinder.utils;

import java.io.File;

import org.apache.commons.io.filefilter.AbstractFileFilter;

/**
 * 文件过滤器
 * 对文件夹和文件进行过滤
 * @author ryuu.kk
 *
 */
public class FileTypeFilder extends AbstractFileFilter {
	
	private boolean isFile = false;
	private boolean isDirectory = false;
	
	public enum TYPE {
		FILE,
		FOLDER,
		ALL
	}
	public FileTypeFilder(TYPE x) {
		if (TYPE.FILE.equals(x)) {
			isFile = true;
		}
		if (TYPE.FOLDER.equals(x)) {
			isDirectory = true;
		}
		if (TYPE.ALL.equals(x)) {
			isFile = true;
			isDirectory = true;
		}
	}
	
	@Override
	public boolean accept(File pathname) {
		
		if (isFile && isDirectory) {
			return true;
		}
		if (isDirectory) {
			return pathname.isDirectory();
		} else {
			return pathname.isFile();
		}
	}
}